package com.da.javatest.leetCode2;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class Code590 {
    private List<Integer> result = new ArrayList<>();

    public static void main(String[] args) {
        Node node = new Node();
        node.val = 1;
        List<Node> nodes = Arrays.asList(new Node(3, null), new Node(2, null), new Node(4, null));
        node.children = nodes;
        new Code590().postorder(node);
    }

    public List<Integer> postorder(Node root) {
        if (root == null) return result;
        if (root.children != null) {
            for (Node child : root.children) {
                postorder(child);
            }
        }
        result.add(root.val);
        return result;
    }
}
